#include "Actor.h"
#include "WalkRight.h"


Actor::Actor()
{
	currentState = NULL;
}

Actor::Actor(Image image, XMFLOAT2 pos)
{
	setImage(image);
	setPosition(pos);
	currentState = NULL;
}

Actor::Actor(vector<Animation*> animations, XMFLOAT2 pos)
{
	setPosition(pos);
	currentState = NULL;
	setImage(*animations.at(0)->getImages().at(0));
	Actor::animations = animations;
}

void Actor::setSpeed(float s)
{
	speed = s;
}

void  Actor::ChangeState(State* newState)
{
	if (currentState != NULL) currentState->Exit();

	currentState = newState;

	currentState->Enter(this);
	
	if (newState->getName().compare("walk_right") == 0)
	{
		newState->setAnimation(Animation::SearchAnimation(animations, "walk_right"));
	}
}

void Actor::Update(double time)
{
	currentState->Do(time);
}


void Actor::Draw(Graphics2D* graphics)
{
	graphics->Draw(&getImage(), getPosition());
}